package com.yj.ccs.abs.web.common.service;

import com.yj.ccs.abs.common.enums.AttachmentType;
import com.yj.ccs.abs.web.common.entity.Attachment;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Copyright 2018 (C) Yunjian-VC
 * Created on : 2018/3/24
 * Author     : Unbelievable9
 **/
@Service
public class CommonService {

    public void setupAttachmentList(List<Attachment> attachmentList, Long referenceId, AttachmentType attachmentType) {
        for (Attachment attachment : attachmentList) {
            attachment.setReference_id(referenceId);
            attachment.setCategory(attachmentType);
        }
    }

    public String getServerRootForRequest(HttpServletRequest request) {
        String scheme = request.getScheme() + "://";
        String serverName = request.getServerName() + ":";
        String serverPort = String.valueOf(request.getServerPort());

        return scheme + serverName + serverPort;
    }
}
